/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <bpf/libbpf.h>
#include "helloworld.skel.h"

static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
{
	return vfprintf(stderr, format, args);
}


int main(int argc, char **argv){
    /* Set up libbpf errors and debug info callback */

	struct helloworld_bpf *skel;
    int err;

    libbpf_set_print(libbpf_print_fn);

    skel = helloworld_bpf__open_and_load();

    if(!skel){
		fprintf(stderr, "Failed to open and load BPF skeleton\n");
		return 1;
    }

    err = helloworld_bpf__attach(skel);
	if (err) {
		fprintf(stderr, "Failed to attach BPF skeleton\n");
		goto cleanup;
	}
	printf("Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` "
	       "to see output of the BPF programs.\n");

    system("cat /sys/kernel/tracing/trace_pipe");
cleanup:
	helloworld_bpf__destroy(skel);
    return -err;
}